<?php
/**
 * Created by IntelliJ IDEA.
 * User: wanglu
 * Date: 2017/9/5
 * Time: 11:05
 */

/**
 * Created by wanglu on 2017/9/5.
 */
class Project_content_service extends MY_Service
{


    public function __construct()
    {
        parent::__construct();
        $this->load->model('project_content_temp_model');
    }

    public function get_project_content($pid, $lang_id) {
        return $this->project_content_temp_model->getRecords(array('pid'=> $pid, 'lang_id'=> $lang_id));
    }

    public function save_or_update_temp_content($pkey, $pid, $lang_id, $content) {
        $dbexits = $this->project_content_temp_model->getRecord(array('pkey'=> $pkey, 'pid'=> $pid, 'lang_id'=> $lang_id));

        //创建
        if (empty($dbexits)) {
            $content = array(
                'pkey'=> $pkey,
                'lang_id' => $lang_id,
                'content' => $content,
                'pid'=> $pid,
                'updatetime'=> time(),
                'createtime'=> time()
            );

            return $this->project_content_temp_model->createRecord($content);
        } else {
            return $this->project_content_temp_model->updateRecord(array('content' => $content, 'updatetime'=> time()),  array('pkey'=> $pkey, 'pid'=> $pid, 'lang_id'=> $lang_id));
        }
    }

    public function batch_insert_temp_contents($contents) {
        $this->project_content_temp_model->batch_insertcontents($contents);
    }

}
